import {
	baseUrl
} from '@/config';
const request = (url = '', data = {}, type = 'GET', header = {}) => {
	const access_token = uni.getStorageSync('access_token');
	if (access_token) {
		header['access-token'] = access_token;
	}
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: data,
			header: header,
			dataType: 'json',
		}).then((response) => {
			let [error, res] = response;
			if (res.data.code === 0) {
				uni.showToast({
					title: res.data.msg,
					duration: 2000,
					icon: 'none'
				});
				return;
			}
			resolve(res.data);
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});
}
export default request
